<!doctype html>
<meta charset="utf-8" />
<!-- This test checks whether we compute pointer coordinates correctly for the
     dragstart, dragend, and drop events issued during drag-and-drop operations.
     This test uses nested iframes, because they are a tricky case when
     computing the clientX, clientY values from screen coordinates. Furthermore,
     running this test through LSAN ensures that we reset the drag state
     correctly in all the frames. -->
<link rel="stylesheet" href="resources/event-mouse-coordinates-nested-iframe.css" />
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/event-mouse-coordinates.js"></script>
<style>
</style>

<p>
  Please drag the "Drag Me" box into the "Drop Here" box.
</p>

<iframe id="iframe1" data-source="iframe1-srcdoc"></iframe>

<script id="iframe1-srcdoc" language="text/html">
<!doctype html>
<meta charset="utf-8" />
<link rel="stylesheet" href="resources/event-mouse-coordinates-nested-iframe.css" />
<iframe id="iframe2" data-source="iframe2-srcdoc">
</script>

<script id="iframe2-srcdoc" language="text/html">
<!doctype html>
<meta charset="utf-8" />
<link rel="stylesheet" href="resources/event-mouse-coordinates-nested-iframe.css" />
<iframe id="iframe3" data-source="iframe3-srcdoc">
</script>

<script id="iframe3-srcdoc" language="text/html">
<!doctype html>
<meta charset="utf-8" />
<link rel="stylesheet" href="resources/event-mouse-coordinates.css" />
<aside class="dragged box" draggable="true">
  Drag Me
</aside>

<aside class="dropzone box">
  Drop Here
</aside>
</script>

<script>

promise_test((t) => {
  return loadNestedFrames(document).then((frameDocument) => {
    const dragCenter = elementCenter(frameDocument.querySelector('.dragged'));
    const dropCenter = elementCenter(frameDocument.querySelector('.dropzone'));
    return runDragTest(t, {
      domRoot: frameDocument,
      frameOffset: { x: 90, y: 150 },
      start: { client: dragCenter, page: { x: 250, y: 150 }},
      end: { client: dropCenter, page: { x: 450, y: 350 }},
    });
  });
}, 'Dragging and dropping DOM nodes in an iframe');

</script>
